#! /usr/bin/python

import math

MAX = 10**8

def generatePalindromic():
    palindro = []
    for i in range(1, 10):
	palindro.append(i)
	palindro.append(i*10+i)
	for j in range(10):
	    palindro.append(i*100+j*10+i)
	    palindro.append(i*1000+j*100+j*10+i)
	    for k in range(10):
		palindro.append(i*10**4+j*1000+k*100+j*10+i)
	        palindro.append(i*10**5+j*10000+k*1000+k*100+j*10+i)
		for l in range(10):
		    palindro.append(i*10**6+j*100000+k*10000+l*1000+k*100+j*10+i)
		    palindro.append(i*10**7+j*10**6+k*10**5+l*10**4+l*10**3+k*100+j*10+i)
    return palindro

palindro = generatePalindromic()
palindro.sort()

#print palindro
count = 0
ss = 0

final = set()
for p in palindro:
    #if p > 1000: break
    d = 1
    constant = 0
    while(True):	
	constant += d**2  
	if p - constant < 4: break      
	if (p - constant)%(d+1) == 0:
	   sq = d**2*(d+1)**2 + 4*(d+1)*(p-constant)
	   if sq < 0: break
	   t = int(math.sqrt(sq))
	   if t**2 == sq and (t-d*(d+1))%(2*(d+1)) == 0:
	      count += 1
	      final.add(p)
	      #if p == 55: print d, t, sq, constant
	      #print p
	#if p == 55: print d
	d += 1
	

print count

print sum(final)
